package com.rxt.controller;


import com.rxt.common.result.Result;
import com.rxt.model.domain.UUser;
import com.rxt.model.dto.UUserDto;
import com.rxt.model.vo.LoginVo;
import com.rxt.model.vo.PasswordVo;
import com.rxt.service.IUUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 周梓文
 * @since 2023-08-24
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("/uUser")
public class UUserController {
    @Autowired
    private IUUserService userService;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginVo loginVo) {
        return userService.login(loginVo);
    }

    @ApiOperation("获取验证码")
    @GetMapping("/captcha")
    public Result getCode(String phone) {
        return userService.getCaptcha(phone);
    }

    @ApiOperation("获取当前用户信息")
    @GetMapping("/me")
    public Result me() {
        return userService.currentUser();
    }

    @ApiOperation("忘记密码")
    @PostMapping("/forgetPwd")
    public Result forgetPwd(@RequestBody LoginVo loginVo, HttpSession session) {
        return userService.forgetPwd(loginVo, session);
    }

    @ApiOperation("重置密码")
    @PostMapping("/resetPwd")
    public Result resetPwd(@RequestBody PasswordVo pwdVo, HttpSession session) {
        return userService.resetPwd(pwdVo, session);
    }

    @ApiOperation("更新用户信息")
    @PostMapping("/update")
    public Result updateUserInfo(@RequestBody UUserDto userDto) {
        return userService.updateUserInfo(userDto);
    }

    @ApiOperation("退出登录")
    @GetMapping("/logout")
    public Result logout() {
        return userService.logout();
    }
}

